package com.ysd.resourceusestatistics.controller;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.ysd.resourceusestatistics.dao.IConsumeLogDao;
import com.ysd.resourceusestatistics.model.ConsumeLog;
import com.ysd.resourceusestatistics.service.IConsumeLogService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * ConsumeLogController
 */
@RestController
@RequestMapping("/consumeLog")
public class ConsumeLogController {
  @Resource
  private IConsumeLogDao consumeLogDao;
  @Resource
 private IConsumeLogService ConsumeLogService;

  @ApiOperation(value = "查询资源使用", notes = "查询已所有资源")
  @GetMapping
  public List<ConsumeLog> findAll() {

    return consumeLogDao.findAll();

  }
  @ApiOperation(value = "添加资源",notes = "添加资源")
	@PostMapping
	public ConsumeLog add(@RequestBody ConsumeLog c) {

		return consumeLogDao.save(c);
		
	}

  @ApiOperation(value = "删除资源", notes = "根据id删除资源")
  @DeleteMapping("/{id}")
  public String del(@PathVariable("id") Integer id) {

    return "del";

  }

  @ApiOperation(value = "批量删除", notes = "根据id批量删除")
  @DeleteMapping
  public int deleteInBatch(@PathVariable Integer id) {

    return consumeLogDao.deleteInBatch(id);

  }
  @ApiOperation(value = "修改",notes = "根据id修改资源")
  @ApiImplicitParams({
    @ApiImplicitParam(name ="cardNo",value = "卡号",required = true,paramType = "path"),
    @ApiImplicitParam(name ="inTime",value = "进入时间",required = true,paramType = "path"),
    @ApiImplicitParam(name ="lastTime",value = "最后一次离开时间",required = true,paramType = "path"),
    @ApiImplicitParam(name ="outTime",value = "离开时间",required = true,paramType = "path"),
    @ApiImplicitParam(name ="readRoomId",value = "资源室id",required = true,paramType = "path")
  })
  @PutMapping("/{id}")
  public int editCL(@PathVariable Integer id,@PathVariable String cardNo,@PathVariable Date inTime,@PathVariable Date lastTime,@PathVariable Date outTime,@PathVariable Integer readRoomId){
    return consumeLogDao.editCL(id,cardNo, inTime, outTime, readRoomId);
  }
@ApiOperation(value = "刷卡",notes = "刷卡")
@ApiImplicitParams(
{

@ApiImplicitParam(name = "readRoomId",value = "资源室编号",required = true,paramType = "path")

}

)
@PutMapping("/{readRoomId}/{cardNo}/{inOrOut}")
public ConsumeLog swipeLog(@PathVariable Integer readRoomId,@PathVariable String cardNo,@PathVariable boolean inOrOut){


return ConsumeLogService.swipingCard(readRoomId, cardNo, inOrOut);

}

}